﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using WebFormsMvp.Contrib.Models;
using WebFormsMvp.Contrib.Data.Services;
using System.Web;
using WebFormsMvp.Contrib.Data.Models;
using WebFormsMvp.Contrib.Presenters;
using System;

namespace WebFormsMvp.Contrib.Tests
{
    [TestClass]
    public class NewsArticlePresenterTest
    {
        [TestMethod]
        public void Load_From_QueryString()
        {
            //Arrange
            var view = MockRepository.GenerateStub<IView<NewsArticleModel>>();
            var dataService = MockRepository.GenerateMock<INewsService>();
            dataService.Expect(d => d.GetNewsArticle(Arg<int>.Is.Anything)).Return(MockRepository.GenerateMock<INewsArticle>());

            var httpContext = MockRepository.GenerateMock<HttpContextBase>();
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            httpContext.Expect(h => h.Request).Return(httpRequest);
            httpRequest.Expect(r => r.QueryString["id"]).Return("0");

            var presenter = new NewsArticlePresenter(view, dataService) { HttpContext = httpContext };

            //Act
            view.Raise(v => v.Load += null, this, EventArgs.Empty);
            presenter.ReleaseView();

            //Assert
            Assert.IsNotNull(view.Model.NewsArticle);
            dataService.VerifyAllExpectations();
            httpContext.VerifyAllExpectations();
            httpRequest.VerifyAllExpectations();
        }
    }
}
